package com.falcon.service.impl;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.hutool.core.bean.BeanUtil;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.swan.mybatis.condition.Condition;
import com.falcon.mvc.domain.BasePager;
import com.falcon.core.utils.BeanUtils;

import com.falcon.domain.po.ListColumnPO;
import com.falcon.domain.dos.ListColumnDO;
import com.falcon.domain.req.ListColumnQuery;
import com.falcon.domain.req.ListColumnRequest;

import com.falcon.mapper.IListColumnMapper;
import com.falcon.service.IListColumnService;


@Slf4j
@Service
public class ListColumnService implements IListColumnService {

    @Autowired
    private IListColumnMapper listColumnMapper;

    @Override
    public Long save(ListColumnRequest request){
        ListColumnPO listColumnPO = BeanUtil.copyProperties(request, ListColumnPO.class);

        this.listColumnMapper.insertNotNull(listColumnPO);

        return listColumnPO.getId();
    }

    @Override
    public Boolean update(Long id, ListColumnRequest request){

        ListColumnPO listColumnPO = BeanUtil.copyProperties(request, ListColumnPO.class);
        listColumnPO.setId(id);

        return this.listColumnMapper.updateNotNull(listColumnPO);
    }

    @Override
    public Boolean deleteById(Long id) {

        return this.listColumnMapper.deleteById(id);
    }

    @Override
    public ListColumnDO queryById(Long id){

        ListColumnPO listColumnPO = this.listColumnMapper.selectById(id);

        ListColumnDO listColumnDO = BeanUtil.copyProperties(listColumnPO, ListColumnDO.class);

        return listColumnDO;
    }


    @Override
    public List<ListColumnDO> queryList(ListColumnQuery request){

        Condition condition = request.toCondition();

        List<ListColumnPO> poList = this.listColumnMapper.selectList(condition);

        List<ListColumnDO> doList = BeanUtil.copyToList(poList, ListColumnDO.class);

        return doList;
    }

    @Override
    public BasePager<ListColumnDO> queryPager(ListColumnQuery request){


        PageInfo<ListColumnPO> pageInfo = PageHelper.startPage(request.getPage(), request.getPageSize())
                .doSelectPageInfo(() -> this.listColumnMapper.selectList(request.toCondition()));

        return BeanUtils.toPager(pageInfo, ListColumnDO.class);
    }

    @Override
    public int batchDelete(List<Long> ids) {

        return this.listColumnMapper.deleteByIds(ids);
    }


}
